package com.course.controller;

import com.course.entity.ResultBody;
import com.course.service.UserManService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/UserManagement")
@CrossOrigin(origins="*")
public class UserManController {
    @Autowired
    private UserManService userManService;
//删除用户（管理员端）
    @RequestMapping("/delectUser")
    public ResultBody delectUser(@RequestBody Map<String,Object> map) {
        if (map.get("id") == null) {
            return new ResultBody(404, "缺少参数", false);
        }
        return userManService.delectUser(map);
    }
//更新用户信（管理员端）
    @RequestMapping("/updateUser")
    public ResultBody updateUser(@RequestBody Map<String,Object> map) {
        if(map.get("id")==null)
        {
            return new ResultBody(404,"缺少参数",false);
        }
        if(map.get("sex")==null&&map.get("userclass")==null&&map.get("name")==null&& map.get("phone")==null&& map.get("address")==null&& map.get("age")==null&&map.get("usernumber")==null&&map.get("college")==null)
        {
            return new ResultBody(404,"缺少参数",false);
        }
        return userManService.updateUser(map);
    }
//增加用户（管理员端）
    @RequestMapping("/addUser")
    public ResultBody addUser(@RequestBody Map<String,Object> map) {
        if(map.get("sex")==null||map.get("name")==null|| map.get("phone")==null||map.get("address")==null||map.get("age")==null||map.get("userclass")==null||map.get("usernumber")==null||map.get("college")==null)
        {
            return new ResultBody(404,"缺少参数",false);
        }
        return userManService.addUser(map);
    }
    @RequestMapping("/displayUser")
    public ResultBody displayUser() {
        return userManService.displayUser();
    }

    @RequestMapping("/addteacher")
    public ResultBody addteacher(@RequestBody Map<String,Object> map) {
        if(map.get("sex")==null||map.get("name")==null|| map.get("phone")==null||map.get("address")==null||map.get("age")==null||map.get("userclass")==null||map.get("usernumber")==null||map.get("college")==null)
        {
            return new ResultBody(404,"缺少参数",false);
        }
        return userManService.addteacher(map);
    }

    @RequestMapping("/displayteacher")
    public ResultBody displayteacher() {
        return userManService.displayteacher();
    }
}


